package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-08-30
 * Time: 17:56
 */
public class Demo5 {
    //线程等待
    public static void main(String[] args) {
        long begin = System.currentTimeMillis();
        Thread thread1 = new Thread(() -> {
            int a = 0;
            for(long i = 0; i < 10_0000_0000; i++){
                a++;
            }
        });
        Thread thread2 = new Thread(() -> {
            int a = 0;
            for(long i = 0; i < 10_0000_0000; i++){
                a++;
            }
        });
        thread1.start();
        thread2.start();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("并发执行的时间:" + (end - begin) + "ms");
    }
}
